package ControllerSrevlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import MYJDBC.jdbc;

/**
 * Servlet implementation class BlueVideoFedSeed
 */
@WebServlet("/BlueVideoFedSeed")
public class BlueVideoFedSeed extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BlueVideoFedSeed() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		jdbc jc = new jdbc();
		request.setAttribute("SqlUser",jc.getSqlUser());
		request.setAttribute("SqlPass",jc.getSqlPass());
		request.setAttribute("SqlName", jc.getSqlName());
		request.getRequestDispatcher("FedBackMsg.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		String userid = request.getParameter("userid");
		String fedtext = request.getParameter("fedtext");
		int uid = Integer.parseInt(userid);
		
		jdbc jc = new jdbc();
		request.setAttribute("SqlUser",jc.getSqlUser());
		request.setAttribute("SqlPass",jc.getSqlPass());
		request.setAttribute("SqlName", jc.getSqlName());
		try {
			jc.SqlUpdate("insert into user_fed (fedtext,user_id) values ('"+fedtext+"',"+uid+");");
			jc.UpdateClose();
			request.setAttribute("fedmsg", 1);
			request.getRequestDispatcher("FedBackMsg.jsp").forward(request, response);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
